<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
  <title>后台管理系统</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link href="/resources/css/dpl-min.css" rel="stylesheet" type="text/css" />
  <link href="/resources/css/bui-min.css" rel="stylesheet" type="text/css" />
  <link href="/resources/css/page-min.css" rel="stylesheet" type="text/css" />
  <link rel="stylesheet" type="text/css" href="/resources/js/editor/skins/default.css">
  <script language="JavaScript" src="/resources/js/editor/kindeditor.js"></script>
  <script language="JavaScript" src="/resources/js/editor/zh_CN.js"></script>
</head>
<body>

<div class="container">
  <form id="J_Form" class="form-horizontal" action="/advert/save">
    <input type="hidden" name="id" value="${data.id}"/>
    <div class="row">
      <div class="control-group span20">
        <label class="control-label"><s>*</s>标题：</label>
        <div class="controls">
          <input name="title" type="text" data-rules="{maxlength:20}" value="${data.title}" class="input-normal control-text" style="width:200px;">
        </div>
      </div>
    </div>

    <div class="row">
      <div class="control-group span20">
        <label class="control-label">排序：</label>
        <div class="controls">
          <input name="sort" type="text" data-rules="{maxlength:10,number:true}" value="${data.sort}" class="input-normal control-text">
        </div>
      </div>
    </div>

    <div class="row">
      <div class="control-group span20">
        <label class="control-label"><s>*</s>广告图片：</label>
        <div id="J_Uploader">

        </div>
        <input type="hidden" name="img" id="img" value="${data.img}"/>
      </div>
    </div>



    <div class="row form-actions actions-bar">
      <div class="span13 offset3 ">
        <button type="submit" class="button button-primary">保存</button>
       <button type="button" class="button" onclick="back()">返回</button>
      </div>
    </div>
  </form>
</div>
<script type="text/javascript" src="/resources/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="/resources/js/sea.js"></script>
<script type="text/javascript" src="/resources/js/bui-min.js"></script>
<script type="text/javascript" src="/resources/js/config-min.js"></script>


<script type="text/javascript">
  BUI.use('common/page'); //页面链接跳转
  BUI.use(['bui/tree','bui/form','bui/uploader'],function (Tree,Form,Uploader) {

    var form = new Form.HForm({
      srcNode : '#J_Form',
      submitType:"ajax",
      listeners:{
        beforesubmit:function(){
          //图片
          var images = $("#J_Uploader img");
          var imgstr = "";
          for(var i = 0; i < images.length; i++) {
            if(i==0){
              imgstr = $(images[i]).attr("src");
            }
          }
          $("#img").val(imgstr);
          return true;
        }
      },
      callback:function(data){
        BUI.Message.Alert(data.msg,function(){
          if(data.success){
            back();
          }
        },'info');
      }
    });

    form.render();

    var uploader = new Uploader.Uploader({
      //指定使用主题
      theme: 'imageView',
      render: '#J_Uploader',
      url: '/upload/buiUpload',
      queue: {
        resultTpl:{
          'success': '<div class="success"><img src="{url}" title="{name}" style="height: 100%;width:100%;"/></div>',
          'error': '<div class="error"><span class="uploader-error">{msg}</span></div>'
        }
      },
      rules: {
        //文的类型
//        ext: ['.png,.jpg','文件类型只能为{0}'],
        //上传的最大个数
        max: [5, '文件的最大个数不能超过{0}个'],
        //文件大小的最大值,单位也是kb
        maxSize: [1024, '文件大小不能大于1M']
      }
    }).render();

    //回显图片
    var img = '${data.img}';
    if(img!= ''){
      $("#J_Uploader ul").append('<li class="bui-queue-item bui-queue-item-success"  style="height: 100%;"><div class="success">' +
              '<img src="'+img+'" style="height: 100%;width:100%;"></div> <span class="action"><span class="bui-queue-item-del">删除</span></span></li>');

    }
  });

  function back(){
    top.topManager.openPage({
      id : 'advert_list',
      isClose : true
    });
    top.topManager.reloadPage('advert_list');
  }
</script>

<body>
</html> 